<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>旺族快递</title>

    <link href="/css/common.css" rel="stylesheet">
    <link href="/css/main-header.css" rel="stylesheet">
    <link href="/css/index.css" rel="stylesheet">

    <link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.2/style/weui.min.css">
    <link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.0/css/jquery-weui.min.css">

</head>
<body>

<% include main-header.ejs %>

<div class="main1">
    <div class="main-center clearfix">

        <% if (login){ %>
            <h1>欢迎！<%= loginUser.username %></h1>

            <div class="main-btn-box">
                <div class="main-btn-box-item"><a href="/newOrderForm">快速下单</a></div>
                <div class="main-btn-box-item"><a href="/myOrderForm">我的订单 <%= count_myOrderForm %></a></div>

                <% if (login && (loginUser.userType === "boss" || loginUser.userType === "admin")){ %>
                    <div class="main-btn-box-item"><a href="/allOrderForm">全部订单 <%= count_allOrderForm %></a></div>
                    <div class="main-btn-box-item"><a href="/undoneOrderForm">未完成订单 <%= count_undoneOrderForm %></a></div>
                    <div class="main-btn-box-item"><a href="/discardOrderForm">废弃订单</a></div>
                    <div class="main-btn-box-item"><a href="/adminManage">管理员管理</a></div>
                <% } %>

            </div>





        <% } else {%>

            <h2>下单啦！</h2>

            <h3>登录后即可下单！</h3>


            <p class="main1-text">请填写您的常用QQ号码，以便我们在需要时联系您</p>

            <form class="main1-form" id="main1-form">
                <div class="weui-cells weui-cells_form">

                    <div class="weui-cell">
                        <div class="weui-cell__hd">
                            <label class="weui-label" for="main1-form-username">QQ号</label>
                        </div>
                        <div class="weui-cell__bd">
                            <input
                                    class="weui-input"
                                    id="main1-form-username"
                                    name="username"
                                    type="Number"
                                    placeholder="请输入您的QQ号"
                            >
                        </div>
                    </div><!--weui-cell-->

                    <input class="weui-btn weui-btn_primary btn-login" id="main1-form-login" type="submit" value="登录">
                </div>


            </form>
        <% } %>

    </div>
</div>

<!--<a href="tencent://AddContact/?fromId=45&fromSubId=1&subcmd=all&uin=651786809&website=www.oicqzone.com">点击添加我的QQ为好友</a>-->
<!--<a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=651786809" target="class">ACM</a>-->
<!--<a  href="http://shang.qq.com/email/stop/email_stop.html?qq=651786809-->
<!--&sig=a1c657365db7e82805ea4b2351081fc3ebcde159f8ae49b1&tttt=1"-->
    <!--target="_blank">点击我加为好友</a>-->

<script src="https://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.0/js/jquery-weui.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-validate/1.17.0/jquery.validate.min.js"></script>

<script src="/js/main-header.js"></script>

<script>
    $(document).ready(function () {
        var data_new,
            data_old;


        // 登录注册一体，用户输入手机号（用户名），后台与数据库比对，若存在则调取用户信息，若不存在，创建用户

        $("#main1-form").validate({
            rules: {
                username: {
                    required: true,
                    digits: true
                }
            },
            messages: {
                username: {
                    required: "请填写您的常用QQ号码",
                    digits: "请填写正确的QQ号码"
                }
            },
            focusInvalid: true,
            submitHandler: function () {
                data_new = {
                    "username": $("#main1-form-username").val().toString()
                };
                $.post("/doLogin", data_new, function (result) {
                    if (result === 1 || result === 2){  // 登录/注册成功
                        window.location = "/";
                    }
                })
            },
            errorElement: "p"  // 错误标签用<p>
        })

    });
</script>

</body>
</html>